package com.tn.wservice.validator;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import com.tn.bo.POHeader;
import com.tn.bo.POLineItem;
import com.tn.service.ContextService;
import com.tn.service.dwr.jaxws.CreateOrSavePurchaseOrder;
import com.tn.wservice.validator.IValidationResult.Result;

public class TestValidator implements BeanFactoryAware {

	private List<IValidator> poHeaderValidators;

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		System.out.println("Jai Baberi");

		NotNullValidator nullValidator = (NotNullValidator) ContextService.getInstance().getBean("notNullValidator");;

		IValidationResult result = nullValidator
				.validate(new CreateOrSavePurchaseOrder());
		if (result.getResult() == Result.SUCCESS) {
			System.out.println("Validations completed successfully");
		} else {
			System.out.println("Validations error => " + result.getErrorMsgs());
		}

		AtleastNNotNullValidator nVal = (AtleastNNotNullValidator) ContextService.getInstance().getBean("atleastNNotNullValidator");
		
		IValidationResult nResult = nVal.validate(new CreateOrSavePurchaseOrder());
		
		System.out.println(nResult.getResult() + " : " + nResult.getErrorMsgs());
		
		String format = "[0-9]{2}-[0-9]{7}";
		System.out.println("Matches result " + ("98-9459999".matches(format)));

		System.out.println("Program Completed");
	}

	private BeanFactory beanFactory;

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

	public void validate(POHeader poHeader) {
		// this.poHeaderValidators

		List<POLineItem> orderLineItems = poHeader.getOrderLineItems();
		for (POLineItem lineItem : orderLineItems) {
			this.validate(lineItem);
		}
	}

	public void validate(POLineItem lineItem) {
		// this.lineValidators
	}

}
